#!/bin/bash
# this requires sqlite3-pcre
DB=/home/themusicgod1/TDL/urls.db
sqlite3 $DB -line "select id, lower(url) from news WHERE url like \""$1"\" and url REGEXP '(.*[A-Z].*)' ;";


TEMPFILE=`mktemp`
# echo "TEMPFILE" $TEMPFILE
sqlite3 $DB -line "select id, lower(url) from news WHERE url like \""$1"\" and url REGEXP '(.*[A-Z].*)' ;" > $TEMPFILE
TV=`wc -l $TEMPFILE | awk -F' ' '{print $1}'`
#echo $TV
if [ $TV -eq "0" ]; then
 exit;
 # we don't need to deal with this
fi

LINE1=`head -n 1 $TEMPFILE | sed -e "s/id = //g"`
LINE2=`tail -n 1 $TEMPFILE | sed -e "s/lower(url)//g" | sed -e "s/ = //g"`
setterm --foreground "red"
echo "update news set url = \""$LINE2"\" where id =" $LINE1 ";"
setterm --foreground "default"
